/*!
 * SharePointFormSubmit
 *
 * 2009 Alex Dinnouti
 * licensed under GPL licenses.
 * 
 * http://code.google.com/p/jquerysharepointform/
 * 
 * Date: 2009-04-16
 * Revision: 1
 *
 * *
 *
 * Allow to send a form within a form in sharepoint
 * 
 * parameters:
 * 	element - the element that contains the form
 * 	method  - post / get
 * 	action  - url
 * 
 * see a example at:
 * http://code.google.com/p/jquerysharepointform/
 * 
*/

(function($){
	$.fn.SharePointFormSubmit = function(element,method,action) {
		var e; // new input element
		var f = document.createElement("form"); // form
			f.method = method;
			f.action = action;			
			f.setAttribute("style","display:none");

		// some jquery requirement form chain several commands I don't think it is necessary
		return this.each(function(){
			// this piece will be optimized better
			$(element).find("input, select, textarea").each(function(){
				e = document.createElement("input")
				e.setAttribute("type", $(this).attr("type"));
				e.setAttribute("id", $(this).attr("id"));
				e.setAttribute("name", $(this).attr("name"));
				e.setAttribute("value", $(this).val());
				e.setAttribute("checked", $(this).attr("checked"));
				e.setAttribute("multiple", $(this).attr("multiple"));
				f.appendChild(e);
			});
			
			// submit the form
			// add the form to the document between </form> and </html>
			// if you put a breakpoint before the submit you will be able to see it
			var s = document.body.appendChild(f);
			s.submit();
		});
	};
})(jQuery);